﻿#region

using System.Windows;
using System.Windows.Navigation;
using NetBay.Core.BusinessEntities;
using Rio.Framework.Pages.AppCode.ApplicationNavigation;

#endregion

namespace Rio.Framework.Pages.ChildWindows
{
    public partial class FolderLinkChildWindow
    {
        #region Readonly & Static Fields

        private readonly Folder _folder;
        private readonly Organization _organization;

        #endregion

        #region Constructors

        public FolderLinkChildWindow(Organization organization, Folder folder)
        {
            InitializeComponent();

            _folder = folder;
            _organization = organization;

            GetFolderLink();
        }

        #endregion

        #region Instance Methods

        private void GetFolderLink()
        {
            if (_folder != null && _organization != null)
            {
                NavigationHelper.Instance.FolderLinkBuilded += Instance_FolderLinkBuilded;
                NavigationHelper.Instance.GetFolderLink(_organization.Identifier, _folder.FolderTypeIdentifier, _folder.Identifier, _folder.Iddoc);
            }
        }

        #endregion

        #region Event Handling

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        private void Instance_FolderLinkBuilded(object sender, NavigationEventArgs e)
        {
            NavigationHelper.Instance.FolderLinkBuilded -= Instance_FolderLinkBuilded;
            txtFolderLink.Text = e.Uri.OriginalString;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Clipboard.SetText(txtFolderLink.Text);
            MessageBox.Show("Le lien a été copié dans le presse-papier.");
        }

        #endregion
    }
}